#include <iostream>
#include <thread>
#include <chrono>

#include "client.h"
#include "data.h"

//void cmain(RShareMemArray &arr) {
void cmain(char *name) {
    RShareMemArray<data_t, 100> arr(name);
    std::cout << "[ C ] name: " << arr.Name() << std::endl;
    std::this_thread::sleep_for (std::chrono::seconds(1));

    int i = 0;
    int32_t idx = 0;

    do {
        std::this_thread::sleep_for (std::chrono::milliseconds(500));

        int32_t length = arr.Length();
        std::cout << "[ C ] arr length: " << length << std::endl;
        if (length > 0) {
            for (idx = 0; idx < length; idx++) {
                data_t *data = arr[idx];
                if (data)
                    std::cout << "[ C ] index: " << idx << ", value: (a:" << data->a << ",b:"<< data->b << ",c:" << data->c << ")" << std::endl;
                else
                    std::cerr << "[ C ] Error. Not found. index: " << idx << std::endl;
            }

            if (length >= 10) break;
        }

        i++;
    } while (i < 30);

    std::cout << "[ C ] Exit." << std::endl;
}
